<?php
namespace Admin\Controller;
use Think\Controller;
class InfoController extends GloableController {
     public function list1(){

      $info=D('payment')->getlist();
      $this->assign("info1",$info);
      $this->display();

    }

    public function list2(){
      $info=D('goods')->getlist();
      $this->assign("info1",$info);
      $this->display();

    }

    public function list4(){//订单搜索
      session('payphone',null);
      session('time',null);
      $info=D('payment')->get_list1();
      $this->assign("info1",$info);
      $this->display();
    }

    public function list3(){//订单详情搜索
      if($_POST['account']){
        session('userphone',null);
        $info=D('goods')->get_list1();
        $this->assign("info1",$info);
        $this->display();
      }else{
       $info=D('goods')->get_phone();
       $this->assign("info1",$info);
       $this->display();
     }
    }

    public function up_address(){
      if(IS_POST){
        $info=D('goods')->up_address1();
        if($info==1){
          $this->redirect('admin/info/list2');
        }else{
          $this->show("<script>alert('无内容变化！')</script>");
          $info=D('goods')->up_address();
          $this->assign("info1",$info);
          $this->display();
        }
      }else{
        $info=D('goods')->up_address();
        $this->assign("info1",$info);
        $this->display();
      }
    }

    public function official(){
      if(IS_POST){
        $info=D('user')->add_user();
        $this->show($info);
      }else{
        $this->display();
      }
    }

    public function zoon(){
      $data = M('relative')->distinct ( true )->order('offical asc')->field ( 'offical' )->select ();
      $this->assign("data",$data);
      $this->display();
    }

    public function zoon1(){
      $info=D('user')->add_user1();
      $this->show($info);
    }

    public function agent(){//总代理
      if(IS_POST){
        $info=D('user')->add_user2();
        $this->show($info);
      }else{
        $data = M('relative')->distinct ( true )->order('offical asc')->field ( 'offical' )->select ();

       
       //官方不对应大区
       //  $info = M('relative')->distinct ( true )->where("zoon!='00'")->order('zoon asc')->field ( 'zoon' )->select ();

       //  foreach ($info as $k => $v) {
       //    if($v['zoon']==""){
       //     $info[$k]['zoon']='00';
       //   }
       // }
        //官方对应大区
        $info=$this->get_zoon_byofficial($data[0]['offical'],2);


       $this->assign("data",$data);
       $this->assign("info",$info);
       $this->display();
     }
   }
  
   //按官方获取大区
   public function get_zoon_byofficial($offical="",$tp=1)
   {
      if($_POST)
      {
         $data=$_POST;
         $offical=$data['offical']?$data['offical']:'';
      }

       $info = M('relative')->distinct ( true )->where("zoon!='00' and offical='$offical'")->order('zoon asc')->field ( 'zoon' )->select ();


       foreach ($info as $k => $v) {
          if($v['zoon']==""){
           $info[$k]['zoon']='00';
         }
       }

       $html="<select id='zoon_data' name='zoon' onchange='change_agent(this)'>";
       foreach ($info as $key => $value) {
         $html.="<option value='".$value['zoon']."'>".$value['zoon']."</option>";
       }
       $html.="</select>";
       if($tp==2)
       {
         return $html;exit();
       }


       $this->ajaxReturn($html,'json');
   }
   //按大区获取总代理
   public function get_agent_byofficial($offical="",$zoon='',$tp=1)
   {
      
      if($_POST)
      {
         $data=$_POST;
         $zoon=$data['zoon']?$data['zoon']:'';
         $offical=$data['offical']?$data['offical']:'';
      }


       $info = M('relative')->distinct ( true )->where("agent!='00' and zoon='$zoon' and offical='$offical'")->order('agent asc')->field ( 'agent' )->select ();

       foreach ($info as $k => $v) {
          if($v['agent']==""){
           $info[$k]['agent']='00';
         }
       }

       $html="<select id='agent_data' name='agent'  >";
       foreach ($info as $key => $value) {
         $html.="<option value='".$value['agent']."'>".$value['agent']."</option>";
       }
       $html.="</select>";
       if($tp==2)
       {
         return $html;exit();
       }


       $this->ajaxReturn($html,'json');
   }
   public function normal(){
    if(IS_POST){
      $info=D('user')->add_user3();
      $this->show($info);
    }else{
      $data = M('relative')->distinct ( true )->order('offical asc')->field ( 'offical' )->select ();

      // $info = M('relative')->distinct ( true )->where("zoon!='00'")->order('zoon asc')->field ( 'zoon' )->select ();
      // foreach ($info as $k => $v) {
      //   if($v['zoon']==""){
      //     $info[$k]['zoon']='00';
      //   }
      // }
      //官方对应大区
      $info=$this->get_zoon_byofficial($data[0]['offical'],2);


      // $agent = M('relative')->distinct ( true )->where("agent!='00'")->order('agent asc')->field ( 'agent' )->select ();
      // foreach ($agent as $k => $v) {
      //   if($v['agent']==""){
      //     $agent[$k]['agent']='00';
      //   }
      // }

      $offical=$data[0]['offical'];

      //官方对应大区
      // $zoon = M('relative')->distinct ( true )->where("zoon!='00' and offical='$offical'")->order('zoon asc')->field ( 'zoon' )->select ();

      $agent=$this->get_agent_byofficial('A','',2);


      $this->assign("data",$data);
      $this->assign("info",$info);
      $this->assign("agent",$agent);
      $this->display();
    }
  }

  public function payment(){//后台确认支付
    $data['id']=I('pk');
    $data2['user']=M('pay')->where($data)->getField('user');
    $data2['state']=1;
    $data1['payment']=1;
    $data1['time']=date("Y-m-d",time());
    $info=M('goods')->where($data2)->save($data1);
    $data3['payment']=1;
    $info=M('pay')->where($data)->save($data3);
    $this->redirect('Info/list1');
  }

  public function activity(){
    if(IS_POST){
      $data=I('');
      $info=M('activity')->add($data);
      if($info){
        $this->redirect("admin/Info/acinfo");
      }else{
        $this->redirect("admin/Info/activity");
      }
    }else{
      $this->display();
    }
  }


  public function acinfo(){
    $info=D('activity')->get_info();
    $this->assign("info",$info);
    $this->display();
  }

  public function up_acinfo(){
    if(IS_POST){
      $info=D('activity')->up_acinfo();
      if($info){
        $this->redirect('admin/Info/acinfo');
      }else{
        $id=I('id');
        $this->redirect('admin/Info/up_acinfo',array("pk"=>$id));
      }
    }else{
     $info=D('activity')->get_info1();
     $this->assign("info",$info);
     $this->display();
   }
 }

 public function export1(){
  $this->display();
}

public function export2(){
  $this->display();
}



public function delete(){//删除活动
  $info=D('activity')->deleteac();
  $this->redirect('admin/info/acinfo');
}

public function sinfo(){//获取授权者信息
    

   //搜索条件
   $wechat=I("wechat",'');
   $phone=I("phone",'');
   $address=I("address",'');
   if(strstr($wechat,"%"))
    {$wechat=urldecode($wechat);}
     if(strstr($phone,"%"))
    {$phone=urldecode($phone);}
     if(strstr($address,"%"))
    {$address=urldecode($address);}


   
   $field_ar=array('wechat' => $wechat,'phone' => $phone,'address' =>$address );
   $page=I("p",1,"int");

   // $type=I("type",1,'int');
   //  //不同列表
   // switch ($type) {
   //   case 1:
   //     $field_ar['state']='1';
   //     break;
   //   case 2:
   //     $field_ar['state']='0';
   //     break;
     
   //   default:
   //     break;
   // } 
  

   $this->assign("wechat",$field_ar['wechat']);
   $this->assign("phone",$field_ar['phone']);
   $this->assign("address",$field_ar['address']);
   

    $info=D('relative')->get_list_granted($page,10,$field_ar);
    $this->assign("info1",$info);
    $this->display();
}

//升降级日志
public function lift_log(){//获取授权者信息
    

   //搜索条件
   $wechat=I("wechat",'');
   $phone=I("phone",'');
   $address=I("address",'');
   if(strstr($wechat,"%"))
    {$wechat=urldecode($wechat);}
     if(strstr($phone,"%"))
    {$phone=urldecode($phone);}
     if(strstr($address,"%"))
    {$address=urldecode($address);}


   
   $field_ar=array('wechat' => $wechat,'phone' => $phone,'address' =>$address );
   $page=I("p",1,"int");

   $type=I("tp",1,'int');
   $this->assign("tp",$type);

  

   $this->assign("wechat",$field_ar['wechat']);
   $this->assign("phone",$field_ar['phone']);
   $this->assign("address",$field_ar['address']);
   

    $info=D('Liftlog')->get_list($type,$page,10,$field_ar);
    $this->assign("info1",$info);
    $this->display();
}


public function sdelete(){//删除授权
  $info=D('relative')->sdelete();
  $this->redirect('admin/Info/sinfo');
}

public function check(){

   // echo strtotime('2000-10-10');exit;

     //搜索条件
   $wechat=I("wechat",'');
   $phone=I("phone",'');
   $address=I("address",'');
   if(strstr($wechat,"%"))
    {$wechat=urldecode($wechat);}
     if(strstr($phone,"%"))
    {$phone=urldecode($phone);}
     if(strstr($address,"%"))
    {$address=urldecode($address);}


   
   $field_ar=array('wechat' => $wechat,'phone' => $phone,'address' =>$address );
   $page=I("p",1,"int");




   $this->assign("wechat",$field_ar['wechat']);
   $this->assign("phone",$field_ar['phone']);
   $this->assign("address",$field_ar['address']);
   


    $info=D('relative')->get_list($page,10,$field_ar);
    $this->assign("info1",$info);
    $this->display();
  
}

public function check1(){//确认授权
  $info=D('relative')->shouquan();
  $this->show($info);
}

public function sqdelete(){//授权申请删除
  $info=D('relative')->sqdelete();
  $this->show($info);
}
//冻结 解冻
public function frozen_users(){//授权申请删除

  $data['is_frozen']=I('is_frozen');
  $where['id']=I('user_id');
  if($where['id'])
  $info=D('user')->where($where)->save($data);
  
  if($data['is_frozen']==1)
    $result="冻结成功";
  else
    $result="解冻成功";
  


  $this->show($result);
}
public function wpay(){
  if(IS_POST){
    $info=D('payment')->getlist2();
    $this->assign("info1",$info);
    $this->display();
  }else{
    $info=D('payment')->getlist1();
    $this->assign("info1",$info);
    $this->display();
  }
}

public function queren(){
  $data1['id']=I('pk');
  $data['tride_id']=M('payment')->where($data1)->getField('tride_id');
  $info=M('zhifu')->where($data)->select();
  $goods=D('goods')->upgoods($info);
  $data3['stime']=date('Y-m-d',time());
  $data3['payment']=1;
  $info=M('payment')->where($data)->save($data3);
}
}
